<template>
  <div class="toast">
    <i :class="['iconfont', getClass]"></i>
    <span>{{ toastMsg }}</span>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  computed: {
    ...mapState({
      toastMsg: (state) => state.showToast.toastMsg,
      toastType: (state) => state.showToast.toastType
    }),
    getClass() {
      switch (this.toastType) {
        case 'success':
          return 'icon-toast_chenggong'
        case 'danger':
          return 'icon-toast-shibai_huaban'
        case 'warning':
          return 'icon-toast-jinggao'
        default:
          break
      }
    }
  }
}
</script>

<style lang="less" scoped>
.toast {
  position: fixed;
  padding: 10px 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fff;
  left: 50%;
  top: 2px;
  transform: translateX(-50%);
  border-radius: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);

  .iconfont {
    margin-right: 10px;
  }

  .icon-toast-shibai_huaban {
    color: red;
  }

  .icon-toast_chenggong {
    color: green;
  }

  .icon-toast-jinggao {
    color: orange;
  }
}
</style>
